using System;
using System.Collections;
using System.Collections.Generic;
using ADougenSDK;
using ADougenSDK.Storage;
using DemoGame;
using UnityEngine;
using UnityEngine.U2D;
using UnityEngine.UI;
using YooAsset;

public class Lanuch : MonoBehaviour
{
    // Start is called before the first frame update
    private Transform LoadButton;
    private Transform RelesButton;

    public Image img;
    
    private void Awake()
    {
        LoadButton = transform.Find("LoadButton");
        RelesButton = transform.Find("RelesButton");
    }

    
    void Start()
    {

        SRDebug.Init();

        SpriteAtlasManager.atlasRequested += OnLoadAtlas;
        
        StorageManager.Instance.Init(
            new List<StorageBase>()
            {
                new StorageTripleCraze(),
            });

        
        
        
        // // 初始化资源系统
        // YooAssets.Initialize();
        // //
        // // // 创建默认的资源包
        // package = YooAssets.CreatePackage("Initial");
        // YooAssets.SetDefaultPackage(package);
        StartCoroutine(Initialize());
        
        // int gd = StorageManager.Instance.GetStorage<StorageTripleCraze>().Gold;
        // StorageManager.Instance.GetStorage<StorageTripleCraze>().Gold = 10;

        // RealmConfiguration cfg = new RealmConfiguration("/Users/shaoyu.geng/Desktop/UnityWorkSpace/ADougenSDKDemo/default.realm");

        // LogUtil.Log("Path = {0}", Addressables.BuildPath);
        // var test = GameConfigManager.Instance.LevelList;


    }
    
    private IEnumerator Initialize()
    {
        yield return YooAssetManager.Instance.Initialized();
        
        // var test = YooAssetManager.Instance.Package.LoadAssetSync<GameObject>("Assets/AssetsPackage/Common/EventBirthdayBundle/Prefabs/UIBirthdayGiftPack");
        // var pre = test.AssetObject;
        // int id = 0;

        // img.sprite = YooAssetManager.Instance.GetSprite("EventBirthdayBundle", "UI_Bundle_8");

        // var cfg = GameConfigManager.Instance.LevelList;
        // int id = 0;
    }
    
    private void OnLoadAtlas(string atlasPath, Action<SpriteAtlas> onAtlasLoad)
    {
        SpriteAtlas sa = YooAssetManager.Instance.LoadSpriteAtlas(atlasPath);
        onAtlasLoad(sa);
    }
    
    // Update is called once per frame
    void Update()
    {
        
    }
}
